define(function(require, exports, module) {
    "require:nomunge,exports:nomunge,module:nomunge";
    "use strict";
    var $ = require("mokit/jquery");

    var Class = function (ops) {
		this.scrollTop = 0;
		this.obj = $(ops.obj);
		this.view = ops.view;
		this.callback = ops.callback;
		this.isLoading = false;
		
		this.obj.scroll(this.loadMoreList.bind(this));
	};
	
	//加载更多列表
	Class.prototype.loadMoreList = function (context) {
		var me = this;
		//正在加载时不执行新加载
		if (this.isLoading) {
			return;
		}
		var px = this.obj.prop('scrollTop');
		//向上滚动时不执行加载
		if (px < this.scrollTop) {
			return;
		}
		this.scrollTop = px;
		var scrollHeight = this.obj.prop('scrollHeight');
		var height = this.obj.outerHeight();
		var scrollBottom = scrollHeight - px - height;
		if (scrollBottom < 50) {			
			me.isLoading = true;
			me.callback(function (isFresh) {
				me.isLoading = false;
				isFresh && me.view[0][me.view[1]].render();
			});
		}
		return false;
	};
	
	//
    module.exports = function (obj) {
		return new Class(obj);
	};

});